package com.hsogoo.collate.quartz;

import com.google.common.collect.Maps;
import com.hsogoo.collate.constants.Constant;
import com.hsogoo.collate.domain.CollateConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Created by za-huangsaigang on 2018/11/22.
 */
@Slf4j
@Service
public class SchedulerJobCreator {

    public SchedulerJob create(CollateConfig collateConfig){

        SchedulerJob job = new SchedulerJob();
        job.setJobId(String.valueOf(collateConfig.getId()));
        job.setJobName(collateConfig.getTaskName());
        job.setJobGroup(collateConfig.getTaskGroup());
        job.setTriggerName(collateConfig.getTaskName());
        job.setTriggerGroup(Constant.DEFAULT_TRIGGER_GROUP);
        job.setCronExpression(collateConfig.getCron());
        job.setJobClass(CollateJobLauncher.class);
        Map<String, Object> params = Maps.newHashMap();
        params.put(Constant.DEFAULT_PARAMS_KEY, collateConfig);
        job.setJobParams(params);
        return job;

    }

    public SchedulerJob createScanJob(){

        SchedulerJob job = new SchedulerJob();
        job.setJobId("scanJobId");
        job.setJobName("scanJobName");
        job.setJobGroup("scanJobGroup");
        job.setTriggerName("scanTriggerName");
        job.setTriggerGroup(Constant.DEFAULT_TRIGGER_GROUP);
        job.setCronExpression(Constant.SCAN_JOB_CRON);
        job.setJobClass(CollateConfigScanner.class);
        Map<String, Object> params = Maps.newHashMap();
        job.setJobParams(params);
        return job;

    }


}
